package com.haizhi.mespush.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haizhi.mespush.bean.Person;
import com.haizhi.mespush.mapper.PersonMapper;
import com.haizhi.mespush.schedule.MyScheduler;
import com.haizhi.mespush.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: Lixiaofei
 * @date: 2020/6/14 17:23
 */
@Service
public class WorkServiceImpl extends ServiceImpl<PersonMapper,Person> implements WorkService {


    @Override
    public boolean upload(MultipartFile file) {
//        ImportParams params =new ImportParams();
//        params.setTitleRows(0);
//        params.setHeadRows(1);
//        List<PrProjectBuild> list;
//        try {
//            list= ExcelImportUtil.importExcel(
//                    file.getInputStream(),
//                    PrProjectBuild.class,params
//            );
//        }catch (Exception e){
//
//        }
        return true;
    }

    @Override
    @Transactional
    public String changeOrder(String order) {
        order.replaceAll("\"","");
        if(order.contains("\\n")){
            return "有空格";
        }
//        String a = order.substring(order.length()-3);
//        if(!a.equals(",")){
//            return "要以,结束";
//        }
        String[] s = order.split(",");

        List<Person> list = new ArrayList<>();
        for (int i = 0; i < s.length; i++) {
            String[] b = s[i].split("=");
            Person per = new Person();
            per.setName(b[0]);
            per.setMobile(b[1]);
            per.setNo(i);
            list.add(per);
        }
        List<Person> deList = this.list();
        for(Person p:deList){
            this.removeById(p);
        }
        this.saveBatch(list);

        return "成功";
    }

}
